package com.kasinf.sample.log.controller;

import com.kasinf.framework.common.pojo.CommonResult;
import com.kasinf.framework.common.pojo.PageParam;
import com.kasinf.framework.common.pojo.PageResult;
import com.kasinf.framework.datapermission.core.DataPermission;
import com.kasinf.framework.datapermission.query.QueryGenerator;
import com.kasinf.framework.log.server.dal.dataobject.ApiLogEsDO;
import com.kasinf.framework.log.server.service.EsLogService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author : Kaiser
 * @Date: 2025/6/30  16:38
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("log")
public class LogController {

    private final EsLogService esLogService;

    @GetMapping
    @DataPermission
    public CommonResult<PageResult<ApiLogEsDO>> search(ApiLogEsDO logDO, PageParam param, HttpServletRequest request) {
        logDO.setUserAgent(null);
        LambdaEsQueryWrapper<ApiLogEsDO> queryWrapper = QueryGenerator.ES.initQueryWrapper(logDO, request.getParameterMap());
        PageResult<ApiLogEsDO> pageList = esLogService.getApiLogPageList(param, queryWrapper);
        return CommonResult.success(pageList);
    }

}
